package com.roy.ai.service.tool;

import com.roy.ai.service.AiService;
import com.roy.ai.service.Assistant;
import com.roy.util.AiUtils;
import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.memory.chat.ChatMemoryProvider;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.service.AiServices;

import java.util.Scanner;

/**
 * @author 山顶洞人郑某
 * @className TestService.java
 * @date 2025 04 01
 */
public class TestService {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Assistant assistant = AiServices.builder(Assistant.class)
                .chatLanguageModel(OpenAiChatModel
                        .builder()
                        .modelName(AiUtils.MODEL_NAME)
                        .apiKey(AiUtils.API_KEY)
                        .strictJsonSchema(true)
                       // .responseFormat("json")
                        .build())
               // .chatMemory(MessageWindowChatMemory.withMaxMessages(10))
               // .chatMemoryProvider(o -> MessageWindowChatMemory.withMaxMessages(10)) //开启窗口聊天
                .tools(new ToolService()) //可以调用的工具类
                .build();
        System.out.println("请输入你要做的事情");
        String chat = assistant.chat(scanner.next());
        System.out.println(chat);
    }
}
